import numpy as np
import math
from SAGIN_Progrem.entity.Task import Task


class Formulas:
    dsa = 3.3  # 卫星的传播延迟 单位是ms
    ksi = 1  # 信道增益或者是路径损耗
    zeta = 10e-17  # 是由芯片结构决定的能量转换效率
    sigma = 50  # 高斯噪音-50dB

    def __init__(self, B, P, f):
        # 此三个变量数组，里面的参数详情见readme
        self.communication_value = np.array([B, P, self.sigma])
        self.f = f

    # 极限信道传输速率 R
    def transmission_R(self):
        S = self.communication_value[1] * Formulas.ksi  # S为信道内信号的平均功率
        R = self.communication_value[0] * math.log((1 + S / self.communication_value[2]), 2)
        return round(R, 2)

    # 延迟：通信延迟、计算延迟、传播延迟、等待延迟
    # 传输延迟
    def transmission_Delay(self, task):
        transmission_t = task.size / self.transmission_R()
        return round(transmission_t, 2)

    # 计算延迟
    def compute_Delay(self, task):
        compute_t = task.size_ * task.complex / self.f  # 这里的延迟单位是秒
        compute_t = compute_t * 1000  # 这里将单位转化为毫秒
        return round(compute_t, 2)

    # 卫星传输延迟 向卫星通信通信时会有传播延迟
    def transmission_sa_Delay(self, task):
        transmission_sa_t = self.transmission_Delay(task) + 2 * Formulas.dsa
        return round(transmission_sa_t, 2)

    # 等待延迟 上一个任务的计算延迟
    def wait_Delay(self):
        return 1

    # 能耗
    # 通信能耗  设备传输的所有任务所消耗的能量
    def communication_Energ(self):
        communication_e = self.communication_value[
                              1] * self.transmission_Delay()  # 传输一个任务所用的能量=设备的发射功率乘以传输时间（传输时间就是传输延迟）
        return communication_e

    # 计算能耗
    # def computing_Energ(self, task):
    #     computing_e = self.compute_Delay(task) * Formulas.zeta * self.f ** 2 # 计算一个任务所用的能量
    #     return computing_e

    # 设备间距离：UAV-UAV,UAV-GD,UAV-S,GD-GD,S-S,GD-S
    # UAV-UAV
    def UAV_UAV_Distence(self):
        pass

    # UAV-GD
    def UAV_GD_Distence(self):
        pass

    # UAV-S
    def UAV_S_Distence(self):
        pass

    # GD-GD
    def GD_GD_Distence(self):
        pass

    # S-S
    def S_S_Distence(self):
        pass

    # GD-S
    def GD_S_Distence(self):
        pass


class passion_:

    # 生成柏松分布序列
    def passion(self, lam, size): # lam为λ(期望) size为k是泊松序列的长度
        # 一次生成长度为20的泊松序列
        x = np.random.poisson(lam=lam, size=size)

        return x


if __name__ == '__main__':
    arr = [[3, 5, 7], [2, -1, 8]]  # Python 列表的二维数组

    if any(any(x < 0 for x in row) for row in arr):
        print("数组中包含负数")
    else:
        print("数组中不包含负数")
